package engine

import (
	log "github.com/sirupsen/logrus"
)

type SimpleEngine struct {

}

func (engine SimpleEngine) Run(seeds ...Request) {
	var requestQueue []Request
	for _, r := range seeds {
		requestQueue = append(requestQueue, r)
	}

	for len(requestQueue) > 0 {
		r := requestQueue[0]
		requestQueue = requestQueue[1:]

		parseResult, err := worker(r)
		if err != nil {
			log.Warnf("fetch url %s error %s" , r.Url , err.Error())
			continue
		}

		requestQueue = append(requestQueue,parseResult.Requests...)

		for _,item := range parseResult.Items {
			log.Printf("Got Item %v" , item)
		}

	}

}

